package com.tony.juc;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.LockSupport;

/**
 * Created with IntelliJ IDEA.
 *
 * @Title: LockSupportDemo0012
 * @Auther: 皮蛋布丁
 * @Date: 2022/04/10/10:04
 * @Description:
 */
public class LockSupportDemo001 {

    public static String msg = null; //保存信息

    public static void main(String[] args) {

        Thread mainThread = Thread.currentThread(); // 获取当前的主线程
        new Thread(()->{
            try {
                System.out.printf("【%s】准备进行数据的处理操作%n",Thread.currentThread().getName());
                TimeUnit.SECONDS.sleep(2); //模拟数据修改的操作延迟
                msg = "皮蛋布丁"; //修改数据内容
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                LockSupport.unpark(mainThread); //恢复主线程
            }
        },"子线程").start();
        LockSupport.park(mainThread); //挂起主线程
        System.out.println("【主线程】得到最终处理的结果：" + msg);

    }

}
